package com.haha.project0301.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author dsx
 * @date 2021/3/1 19:35
 * @since JDK1.8
 */
@Controller
public class loginController {
    @RequestMapping("/user/login")
    public String login(@RequestParam("username") String username, @RequestParam("password") String password,Model model, HttpSession session){
        if ("admin".equals(username) && "123456".equals(password)){
            session.setAttribute("logined",username);
            return "redirect:/main.html";//重定向到main.html页面,也就是跳转到dashboard页面,这里用的request，采用跳转的方式是为了防止信息泄露
        }else {
            model.addAttribute("err","用户名或密码不正确");
            return "index";
        }
    }
    @RequestMapping("/logout")
    public String logout(HttpSession session){
        System.out.println("退出成功");
        session.invalidate();
        return "redirect:/index.html";

    }
}
